package com.lex.notepad;

import android.app.Dialog;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.WindowDecorActionBar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lex.dialoglibrary.CustomDialog;

/**
 * Created by Administrator on 2016/6/29.
 */
public class RegisterDatabase extends AppCompatActivity{

    private EditText user_reg_name,pass_reg_words;
    private Button zhuce,confirm_dialog_btn;
    private MyDataBaseHelper dbHelper;
    private Dialog dialog;
    private String name,password;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        dbHelper = new MyDataBaseHelper(this, "notepad.db", null, 1);
        user_reg_name = (EditText) findViewById(R.id.user_reg_name);
        pass_reg_words = (EditText) findViewById(R.id.pass_reg_words);
        confirm_dialog_btn = (Button) findViewById(R.id.confirm_dialog_btn);
        dialog = new CustomDialog(RegisterDatabase.this, R.layout.dialog_register);
        zhuce = (Button) findViewById(R.id.zhuce);
        zhuce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                name = user_reg_name.getText().toString();
                password = pass_reg_words.getText().toString();
                if (name.length() <= 0 && password.length() <= 0) {
                    Toast.makeText(RegisterDatabase.this, "用户名或密码为空", Toast.LENGTH_SHORT).show();
                } else if (name.length() <= 0) {
                    Toast.makeText(RegisterDatabase.this, "用户名不能为空", Toast.LENGTH_SHORT).show();
                } else if (password.length() <= 0) {
                    Toast.makeText(RegisterDatabase.this, "密码不能为空", Toast.LENGTH_SHORT).show();
                } else if (name != null && password != null) {
                    dbHelper.getWritableDatabase();
                    SQLiteDatabase db = dbHelper.getWritableDatabase();
                    ContentValues values = new ContentValues();
                    values.put("user_name",name);
                    values.put("pass_word",password);
                    db.insert("notepad",null,values);
                    values.clear();
                }
            }
        });
    }
}